import { Injectable, EventEmitter } from '@angular/core';
import { Subject, Observable } from 'rxjs';

@Injectable()
export class MessageService {

  public serviceEmitter : EventEmitter<any>;

  public offspringEmit : EventEmitter<any>;
  public ancestorsEmit : EventEmitter<any>;

  constructor() { 
    this.serviceEmitter = new EventEmitter();
    this.offspringEmit = new EventEmitter();
    this.ancestorsEmit = new EventEmitter();
  }


  private infoSubject       = new Subject<any>();
  private treeSubject       = new Subject<any>();
  private tableSubject      = new Subject<any>();
  private detailSubject     = new Subject<any>();
  private addSubject        = new Subject<any>();
  private editSubject       = new Subject<any>();
  private checkboxSubject   = new Subject<any>();

  sendInfo(info: any) {
    this.infoSubject.next(info);
  }

  getInfo():Observable<any> {
    return this.infoSubject.asObservable();
  }

  /**
   * 树状图
   */ 
  sendTree(info: any) {
  	this.treeSubject.next(info);
  }

  getTree():Observable<any> {
  	return this.treeSubject.asObservable();
  }

  /**
   * 表格
   */ 
  sendTable(info: any) {
    this.tableSubject.next(info);
  }

  getTable():Observable<any> {
    return this.tableSubject.asObservable();
  }

  /**
   * 新增
   */ 
  sendAdd(info: any) {
    this.addSubject.next(info);
  }

  getAdd():Observable<any> {
    return this.addSubject.asObservable();
  }

  /**
   * 详情
   */ 
  sendDetail() {

  }

  getDetail() {

  }

  /**
   * 修改
   */ 
  sendEdit(info: any) {
    this.editSubject.next(info);
  }

  getEdit():Observable<any> {
    return this.editSubject.asObservable();
  }

  /**
   * 复选框
   */
  sendCheckbox(info: any) {
    this.checkboxSubject.next(info);
  }

  getCheckbox():Observable<any> {
    return this.checkboxSubject.asObservable();
  }

}
